// importM
import 'package:flutter/material.dart';

// ignore: unused_import
import './MyIcon.dart';

import './res/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(
          title: Text("Flutter App", style: TextStyle(color: Colors.white)),
          backgroundColor: Colors.deepPurple,
        ),
        body: LikeBlog(),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(child: Text("Hello Flutter"));
  }
}

class Asp extends StatelessWidget {
  const Asp({super.key});

  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 2 / 1,
      child: Container(color: Colors.black45),
    );
  }
}

class Cards extends StatelessWidget {
  const Cards({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Card(
          // Card边框效果
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          // 卡片阴影深度
          elevation: 5,
          margin: EdgeInsets.all(10),
          child: Column(
            children: [
              ListTile(
                title: Text("张三", style: TextStyle(fontSize: 20)),
                subtitle: Text("高级工程师"),
              ),
              Divider(),
              ListTile(leading: Icon(Icons.phone), title: Text("13945215474")),
              ListTile(leading: Icon(Icons.home), title: Text("成都市高新区")),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.all(10),
          elevation: 5,
          child: Column(
            children: [
              ListTile(
                title: Text("李四", style: TextStyle(fontSize: 20)),
                subtitle: Text("Flutter高级工程师"),
              ),
              Divider(),
              ListTile(leading: Icon(Icons.phone), title: Text("1394566789")),
              ListTile(leading: Icon(Icons.home), title: Text("成都市武侯区")),
            ],
          ),
        ),
      ],
    );
  }
}

class LikeBlog extends StatelessWidget {
  const LikeBlog({super.key});

  List<Widget> _initCardDate() {
    return listData.map((value) {
      return Card(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        margin: EdgeInsets.all(10),
        elevation: 10,
        child: Column(
          children: [
            AspectRatio(
              aspectRatio: 16 / 8,
              child: Image.network(
                value["imageUrl"],
                fit: BoxFit.cover,
              ),
            ),
            ListTile(
              leading: CircleAvatar(
                backgroundImage: NetworkImage(
                  value["imageUrl"],
                ),
              ),
              title: Text(value["title"]),
              subtitle: Text(value["author"]),
            ),
          ],
        ),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: _initCardDate(),
    );
  }
}
